package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.constant.AutoFillConstant;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 类描述：
 */
@Mapper
public interface DishMapper {
    @Select("select count(*) from dish where category_id = #{id} and status = 1")
    Integer countByCategory(Long id);

    @AutoFill(value = OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into dish (name, category_id, price, image,description,status, create_time, update_time, create_user, update_user) values (#{name}, #{categoryId}, #{price},  #{image}, #{description},#{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void save(Dish dish);

    Page<DishVO> page(String name, Integer categoryId, Integer status);


    @Select("select status from dish where id = #{id}")
    Integer status(Long id);

    @Delete("delete from dish where id = #{id}")
    void delete(Long id);

    @Select("select * from dish where id = #{id}")
    Dish getDishById(Long id);


    @Select("select c.name from dish d join category c on d.category_id = c.id where d.id = #{id}")
    String getCategoryNameById(Long id);


//    @Select("select d.*,c.name as catrgoryName from dish d left join category c on d.category_id = c.id where d.id = #{id}")
//    DishVO getDishById(Long id);

    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);


    @Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<Dish> list(Dish dish);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> listById(Integer categoryId);
}
